const fs = require("fs");
const path = require("path");
const moment = require("moment");

function access(log) {

    let time = moment().format("YYYY-MM-DD");
    let fileName = time + ".access.log";
    let filePath = path.join(__dirname, "../logs/", fileName);
    
    //创建writeStream
    const writeStream = fs.createWriteStream(filePath, {
        flags: "a"
    });
    //写入文件
    writeStream.write(log + "\n");
}

module.exports = access;